home *** CD-ROM | disk | FTP | other *** search
/ Nebula 2 / Nebula Two.iso / SourceCode / AdobeExamples / NX_LineDraw / DrawViewWraps.psw < prev    next >
Text File  |  1995-06-12  |  5KB  |  165 lines

  1.  
  2. /*
  3.  * (a)  (C) 1990 by Adobe Systems Incorporated. All rights reserved.
  4.  *
  5.  * (b)  If this Sample Code is distributed as part of the Display PostScript
  6.  *    System Software Development Kit from Adobe Systems Incorporated,
  7.  *    then this copy is designated as Development Software and its use is
  8.  *    subject to the terms of the License Agreement attached to such Kit.
  9.  *
  10.  * (c)  If this Sample Code is distributed independently, then the following
  11.  *    terms apply:
  12.  *
  13.  * (d)  This file may be freely copied and redistributed as long as:
  14.  *    1) Parts (a), (d), (e) and (f) continue to be included in the file,
  15.  *    2) If the file has been modified in any way, a notice of such
  16.  *      modification is conspicuously indicated.
  17.  *
  18.  * (e)  PostScript, Display PostScript, and Adobe are registered trademarks of
  19.  *    Adobe Systems Incorporated.
  20.  * 
  21.  * (f) THE INFORMATION BELOW IS FURNISHED AS IS, IS SUBJECT TO
  22.  *    CHANGE WITHOUT NOTICE, AND SHOULD NOT BE CONSTRUED
  23.  *    AS A COMMITMENT BY ADOBE SYSTEMS INCORPORATED.
  24.  *    ADOBE SYSTEMS INCORPORATED ASSUMES NO RESPONSIBILITY
  25.  *    OR LIABILITY FOR ANY ERRORS OR INACCURACIES, MAKES NO
  26.  *    WARRANTY OF ANY KIND (EXPRESS, IMPLIED OR STATUTORY)
  27.  *    WITH RESPECT TO THIS INFORMATION, AND EXPRESSLY
  28.  *    DISCLAIMS ANY AND ALL WARRANTIES OF MERCHANTABILITY, 
  29.  *    FITNESS FOR PARTICULAR PURPOSES AND NONINFRINGEMENT
  30.  *    OF THIRD PARTY RIGHTS.
  31.  */
  32.  
  33. /*
  34. *    DrawViewWraps.psw
  35. *
  36. *    Here lie the wraps used in DrawView.m for the LineDrawing application.
  37. *    Several ways to draw lines are shown here.  One that is not is to use the
  38. *    single operator functions from the method directly.
  39. *
  40. *    PostScript operators obtain their operands from the stack.
  41. *    As a result the order of placing the operands on the stack is very important.
  42. *    In the examples below,  comments are used in the bound procedures
  43. *    to indicate the operands on stack when the procedure is called.
  44. *    One common problem area is to inadvertently place the operands on 
  45. *    stack in the wrong order. 
  46. *
  47. *    Version:    2.0
  48. *    Author:    Ken Anderson, Ken Fromm
  49. *    History:
  50. *            03-07-91        Added this comment.
  51. */
  52.  
  53. /* StartTime is stored in the interpreter and contains the initial real time */
  54. defineps PSWMarkTime ()
  55.     /StartTime realtime def
  56. endps
  57.  
  58. /* The difference between the current real time and the initial time stored                */
  59. /* in StartTime is returned to the calling procedure in the output arg ElapsedTime. */
  60. defineps PSWReturnTime (|int *ElapsedTime)
  61.     realtime StartTime sub 
  62.     ElapsedTime
  63. endps
  64.  
  65. /*
  66. * This wrap is called in the +newFrame:(NXRect *) frm method to
  67. * define and bind procedures in the interpreter.  These procedures
  68. * are then called from within other wraps. Binding replaces each
  69. * executable operator name with its value.  During execution of the
  70. * procedures, the interpreter encounters the operators themselves
  71. * instead of the names of the operators.  A procedure that has been
  72. * bounded will execute faster than one that has not been bound. 
  73. * Certain caveats pertain; see the red book for further information.
  74. */
  75. defineps PSWDefs ()
  76.     
  77.     /EVB { % BGrect  BGStrWidth BGStrColor BGColor 
  78.         setgray 2 index rectfill
  79.         setgray setlinewidth rectstroke
  80.     } bind def
  81.     
  82.     /DLB { % X1 Y1 X Y LineColor LineWidth
  83.         setlinewidth setgray
  84.         moveto lineto stroke
  85.     } bind def
  86.  
  87.     /DLRB { % i 
  88.         0 1 3 -1 roll 1 sub { % for
  89.             dup PSW exch get setlinewidth
  90.             dup PSC exch get setgray
  91.             dup PSX exch get PSY 2 index get moveto
  92.             dup PSX1 exch get PSY1 2 index get lineto
  93.             stroke pop
  94.         } for
  95.     } bind def
  96.         
  97.     /MLB { % X1 Y1 X Y
  98.         moveto
  99.         lineto
  100.     } bind def
  101.  
  102.     /SLB { % LineColor LineWidth
  103.         setlinewidth
  104.         setgray
  105.         stroke
  106.     } bind def
  107.     
  108. endps
  109.  
  110. /***  Called by -drawWraps ***/
  111. /* Calls the operators from the wrap itself. */
  112. defineps PSWEraseView (float BGColor, BGStrColor, BGStrWidth, BGrect[4])
  113.     BGColor setgray
  114.     BGrect rectfill
  115.     BGStrColor setgray
  116.     BGStrWidth setlinewidth
  117.     BGrect rectstroke
  118. endps
  119.  
  120. /* Calls the operators from the wrap itself. */
  121. defineps PSWDrawLine (float LineWidth, LineColor, X, Y, X1, Y1)
  122.     LineWidth setlinewidth
  123.     LineColor setgray
  124.     X Y moveto
  125.     X1 Y1 lineto
  126.     stroke
  127. endps
  128.  
  129.  
  130. /***  Called by -drawWrapsBind  ***/
  131. /* Places the input args on the stack and calls the EraseViewBind procedure. */
  132. defineps PSWEraseViewBind (float BGColor, BGStrColor, BGStrWidth, BGrect[4])
  133.     BGrect BGStrWidth BGStrColor BGColor EVB
  134. endps
  135.  
  136. /* Places the input args on the stack and calls the DrawLineBind procedure. */
  137. defineps PSWDrawLineBind (float LineWidth, LineColor, X, Y, X1, Y1)
  138.     X1 Y1 X Y LineColor LineWidth DLB
  139. endps
  140.  
  141.  
  142. /***  Called by -drawWrapsRepeat  ***/
  143. /* Defines input args, places the number of repetitions on the stack and then */
  144. /* calls the DrawLineRepeatBind procedure. */
  145. defineps PSWDrawLineRepeatBind (float W[i], C[i], X[i], Y[i], X1[i], Y1[i]; int i)
  146.     /PSW W def
  147.     /PSC C def
  148.     /PSX X def /PSY Y def
  149.     /PSX1 X1 def /PSY1 Y1 def
  150.     i DLRB
  151. endps
  152.  
  153.  
  154. /***  Called by -drawOptimizedStroke  ***/
  155. /* Places the input args on the stack and calls the MakeLineBind procedure. */
  156. defineps PSWMakeLineBind (float X, Y, X1, Y1)
  157.     X1 Y1 X Y MLB
  158. endps
  159.  
  160. /* Places the input args on the stack and calls the StrokeLineBind procedure. */
  161. defineps PSWStrokeLineBind (float LineWidth, LineColor)
  162.     LineColor LineWidth SLB
  163. endps
  164.  
  165.